<template>
  <div>
    <el-card class="box-card">
      <el-table
        ref="multipleTable"
        :data="dismissions"
        tooltip-effect="dark"
        style="width: 100%;"
        v-loading="loading"
        :header-cell-style="{ background: '#f8f8f9', color: '#515a6e' }"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" label="序号" />
        <el-table-column label="头像">
          <template slot-scope="scope">
            <el-image
              style="width: 70px"
              :src="scope.row.employee.empAvatar"
              :preview-src-list="[scope.row.employee.empAvatar]"
              v-if="scope.row.employee.empAvatar"
            ></el-image>
            <span v-else>{{'暂无头像'}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="employee.empName" label="真实姓名" />
        <el-table-column label="性别">
          <template slot-scope="scope">
            <span>{{ scope.row.employee.sex === 1 ?'男': '女' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="离职类型" width="140px">
          <template slot-scope="scope">
            <span
              style="margin-left: 10px"
            >{{ ['主动辞职','辞退','退休','开除','试用不通过'][scope.row.disType-1] }}</span>
          </template>
        </el-table-column>
        <el-table-column label="去向" width="140px" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="scope.row.direction">{{scope.row.direction}}</span>
            <span v-else>暂无</span>
          </template>
        </el-table-column>
        <el-table-column label="离职时间" width="140px">
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span style="margin-left: 10px">{{ scope.row.disDate | formatDate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="备注" width="140px" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="scope.row.disRemark">{{scope.row.disRemark}}</span>
            <span v-else>暂无</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200px">
          <template slot-scope="scope">
            <el-button type="text" @click="handleDel(scope.row.id)" icon="el-icon-delete">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="getDismissions"
        @current-change="getDismissions"
        :current-page="queryInfo.pageNum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
  </div>
</template>

<script>
// import { getTalentPool, entryById, deleteTalent } from "@/api/employee";
import { getDimissionPage, delDismission } from "@/api/dismission";
export default {
  name: "DepartureRecord",
  data() {
    return {
      queryInfo: {
        // 当前页
        pageNum: 1,
        // 页大小
        pageSize: 10,
        // empName: undefined,
      },
      total: 0,
      dismissions: [],
      loading: false,
    };
  },
  created() {
    this.getDismissions();
  },
  methods: {
    async getDismissions() {
      this.loading = true;
      let { code, data } = await getDimissionPage(this.queryInfo);
      if (code === 200) {
        console.log(data);
        this.total = data.total;
        this.dismissions = data.dismissions;
      }
      this.loading = false;
    },
    handleSelectionChange() {},
 
    handleDel(id) {
      this.$confirm("此操作将永久删除该记录, 是否继续?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          //   console.log(id);
          let { code } = await delDismission(id);
          if (code === 200) {
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            this.getDismissions();
          }
        })
        .catch(() => {});
    },
  },
};
</script>

<style scoped lang="scss">
.el-pagination {
  margin: 18px 0px;
  float: right;
}
</style>